package com.hengxinguotong.zhihuichengjian.ui.building;

import com.bigkoo.pickerview.TimePickerView;
import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.adapter.AccidentAddPersonAdapter;
import com.hengxinguotong.zhihuichengjian.adapter.AualityTestAddPicAdapter;
import com.hengxinguotong.zhihuichengjian.adapter.EnterpriseConstructionAdapter;
import com.hengxinguotong.zhihuichengjian.adapter.EnterpriseUserAdapter;
import com.hengxinguotong.zhihuichengjian.bean.Construction;
import com.hengxinguotong.zhihuichengjian.bean.User;
import com.hengxinguotong.zhihuichengjian.picturebrowser.view.TaskBigImgActivity;
import com.hengxinguotong.zhihuichengjian.ui.BaseActivity;
import com.hengxinguotong.zhihuichengjian.ui.SearchNoticedPersonActivity;
import com.hengxinguotong.zhihuichengjian.utils.FileUtil;
import com.hengxinguotong.zhihuichengjian.utils.SPUtil;
import com.hengxinguotong.zhihuichengjian.utils.Utils;
import com.hengxinguotong.zhihuichengjian.widget.font.HXEditTextView;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;
import com.lidroid.xutils.http.RequestParams;

import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.nereo.multi_image_selector.MultiImageSelector;
import me.nereo.multi_image_selector.MultiImageSelectorActivity;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2018/12/28
 */

public class BuildAddActivity extends BaseActivity implements View.OnClickListener, AualityTestAddPicAdapter.OnRecyclerViewClickListener{
    private static final int ADD_CONTACT = 0;
    private static final int ADD_NOTICE = 1;
    private static final int ADD_PIC = 2;

    @BindView(R.id.tv_title_name)
    HXTextView tvTitleName;
    @BindView(R.id.inspect_date_tv)
    HXTextView inspectDateTv;
    @BindView(R.id.reply_date_tv)
    HXTextView replyDateTv;
    @BindView(R.id.remind_date_tv)
    HXTextView remindDateTv;
    @BindView(R.id.test_detail_etv)
    HXEditTextView testDetailEtv;
    @BindView(R.id.contact_rv)
    RecyclerView contactRv;
    @BindView(R.id.notice_rv)
    RecyclerView noticeRv;
    @BindView(R.id.pic_rv)
    RecyclerView picRv;

    private TimePickerView inspectTime, replyTime, remindeTime;
    private Date inspectDate, replyDate, remideDate;

    private List<User> contactPersons, selectContacts;//责任人员数组
    private AccidentAddPersonAdapter contactAdapter;
    private List<User> noticedPersons, selectNotices;//告知人员数组
    private AccidentAddPersonAdapter noticeAdapter;

    private List<Construction> contactConstructions, noticeConstructions;
    private EnterpriseConstructionAdapter contactEnterpriseAdapter, noticeEnterpriseAdapter;

    private List<String> paths;
    private List<String> minPaths;
    private AualityTestAddPicAdapter aualityTestAddPicAdapter;
    private boolean fromEnterprise = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fromEnterprise = getIntent().getBooleanExtra("fromEnterprise", false);
        if(fromEnterprise){
            setContentView(R.layout.activity_build_add_enterprise);
        }else {
            setContentView(R.layout.activity_build_add);
        }
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        tvTitleName.setText("任务下发");

        initTimePicker();

        selectContacts = new ArrayList<>();
        selectNotices = new ArrayList<>();

        if(fromEnterprise){
            contactConstructions = new ArrayList<>();
            contactEnterpriseAdapter = new EnterpriseConstructionAdapter(this, contactConstructions);
            contactEnterpriseAdapter.setOnChildDeleteClickListener(contactDelete);
            contactEnterpriseAdapter.setOnChildHeadClickListener(contactHead);
            contactEnterpriseAdapter.setHasDelete(true);
            contactRv.setAdapter(contactEnterpriseAdapter);
            contactRv.setLayoutManager(getVerticalLinearLayoutManager());

            noticeConstructions = new ArrayList<>();
            noticeEnterpriseAdapter = new EnterpriseConstructionAdapter(this, noticeConstructions);
            noticeEnterpriseAdapter.setOnChildDeleteClickListener(noticeDelete);
            noticeEnterpriseAdapter.setOnChildHeadClickListener(noticeHead);
            noticeEnterpriseAdapter.setHasDelete(true);
            noticeRv.setAdapter(noticeEnterpriseAdapter);
            noticeRv.setLayoutManager(getVerticalLinearLayoutManager());

        }else {
            contactPersons = new ArrayList<User>();
            contactPersons.add(getAddUser());
            contactAdapter = new AccidentAddPersonAdapter(this, contactPersons, new AccidentAddPersonAdapter.OnRecyclerViewClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    if (Utils.ADDPIC.equals(contactPersons.get(position).getHeadPortrait())) {
                        goToContacts();
                    } else {
                        User user = contactPersons.get(position);
                        contactPersons.remove(user);
                        selectContacts.remove(user);
                        contactAdapter.notifyDataSetChanged();
                    }
                }

                @Override
                public void onClick(View v) {

                }
            }, true);
            contactRv.setLayoutManager(getHorizontalLinearLayoutManager());
            contactRv.setAdapter(contactAdapter);

            noticedPersons = new ArrayList<User>();
            noticedPersons.add(getAddUser());
            noticeAdapter = new AccidentAddPersonAdapter(this, noticedPersons, new AccidentAddPersonAdapter.OnRecyclerViewClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    if (Utils.ADDPIC.equals(noticedPersons.get(position).getHeadPortrait())) {
                        goToNotices();
                    } else {
                        User user = noticedPersons.get(position);
                        noticedPersons.remove(user);
                        selectNotices.remove(user);
                        noticeAdapter.notifyDataSetChanged();
                    }
                }

                @Override
                public void onClick(View v) {

                }
            }, true);
            noticeRv.setLayoutManager(getHorizontalLinearLayoutManager());
            noticeRv.setAdapter(noticeAdapter);
        }

        paths = new ArrayList<String>();
        paths.add(Utils.ADDPIC);
        aualityTestAddPicAdapter = new AualityTestAddPicAdapter(this, paths, this, true);
        picRv.setLayoutManager(getHorizontalLinearLayoutManager());
        picRv.setAdapter(aualityTestAddPicAdapter);
    }

    private void goToNotices() {
        Intent intent = new Intent();
        if(fromEnterprise){
            intent.setClass(BuildAddActivity.this, EnterpriseUserSelectActivity.class);
        }else {
            intent.setClass(BuildAddActivity.this, SearchNoticedPersonActivity.class);
        }
        intent.putExtra("noticedPersons", (Serializable) selectNotices);
        intent.putExtra("isLive", true);
        startActivityForResult(intent, ADD_NOTICE);
    }

    private void goToContacts() {
        Intent intent = new Intent();
        if(fromEnterprise){
            intent.setClass(BuildAddActivity.this, EnterpriseUserSelectActivity.class);
            intent.putExtra("type", 1);//1是选择责任人 2是选择告知人
        }else {
            intent.setClass(BuildAddActivity.this, SearchNoticedPersonActivity.class);
        }
        intent.putExtra("noticedPersons", (Serializable) selectContacts);
        intent.putExtra("isLive", true);
        startActivityForResult(intent, ADD_CONTACT);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(data != null){
            switch (requestCode){
                case ADD_PIC:
                    paths = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
                    paths.add(Utils.ADDPIC);
                    if (aualityTestAddPicAdapter != null) {
                        aualityTestAddPicAdapter.setPaths(paths);
                    }
                    break;
                case ADD_NOTICE:
                    if(fromEnterprise){
                        List<User> noticeTemp = (List<User>) data.getSerializableExtra("selectUsers");
                        for (int i = 0; i < noticeTemp.size(); i++) {
                            User user = noticeTemp.get(i);
                            if (!user.isInUsers(selectNotices)) {
                                selectNotices.add(user);
                            }
                        }
                        List<Construction> noticeConstructionTemp = (List<Construction>) data.getSerializableExtra("selectConstructions");
                        for (Construction construction:noticeConstructionTemp){
                            List<User> u1 = construction.getUserList();
                            for (User user:selectNotices){
                                if(user.getConstructionId().equals(construction.getConstructionId())){
                                    u1.add(user);
                                }
                            }
                        }
                        noticeConstructions = noticeConstructionTemp;
                        noticeEnterpriseAdapter.setDataList(noticeConstructions);
                    }else {
                        List<User> noticeTemp = (List<User>) data.getSerializableExtra("selectNoticers");
                        for (int i = 0; i < noticeTemp.size(); i++) {
                            User user = noticeTemp.get(i);
                            if (!user.isInUsers(selectNotices)) {
                                selectNotices.add(user);
                            }
                        }
                        noticedPersons.clear();
                        noticedPersons.add(getAddUser());
                        noticedPersons.addAll(selectNotices);
                        noticeAdapter.notifyDataSetChanged();
                    }

                    break;
                case ADD_CONTACT:
                    if(fromEnterprise){
                        List<User> contactTemp = (List<User>) data.getSerializableExtra("selectUsers");
                        for (int i = 0; i < contactTemp.size(); i++) {
                            User user = contactTemp.get(i);
                            if (!user.isInUsers(selectContacts)) {
                                selectContacts.add(user);
                            }
                        }
                        List<Construction> contactConstructionTemp = (List<Construction>) data.getSerializableExtra("selectConstructions");
                        for (Construction construction:contactConstructionTemp){
                            List<User> u1 = construction.getUserList();
                            for (User user:selectContacts){
                                if(user.getConstructionId().equals(construction.getConstructionId())){
                                    u1.add(user);
                                }
                            }
                        }
                        contactConstructions = contactConstructionTemp;
                        contactEnterpriseAdapter.setDataList(contactConstructions);
                    }else {
                        List<User> contactTemp = (List<User>) data.getSerializableExtra("selectNoticers");
                        for (int i = 0; i < contactTemp.size(); i++) {
                            User user = contactTemp.get(i);
                            if (!user.isInUsers(selectContacts)) {
                                selectContacts.add(user);
                            }
                        }
                        contactPersons.clear();
                        contactPersons.add(getAddUser());
                        contactPersons.addAll(selectContacts);
                        contactAdapter.notifyDataSetChanged();
                    }
                    break;
            }
        }
    }

    private EnterpriseUserAdapter.OnChildDeleteClickListener contactDelete = new EnterpriseUserAdapter.OnChildDeleteClickListener() {
        @Override
        public void onChildDeleteClick(int position, int childPosition) {
            User user = contactConstructions.get(position).getUserList().get(childPosition);
            contactConstructions.get(position).getUserList().remove(user);
            selectContacts.remove(user);
            if(contactConstructions.get(position).getUserList().size() <= 0){
                contactConstructions.remove(position);
            }
            contactEnterpriseAdapter.setDataList(contactConstructions);
        }
    };

    private  EnterpriseUserAdapter.OnChildHeadClickListener contactHead = new EnterpriseUserAdapter.OnChildHeadClickListener() {
        @Override
        public void onChildHeadClick(int position, int childPosition) {
            String headPotrait = contactConstructions.get(position).getUserList().get(childPosition).getHeadPortrait();
            if(!Utils.isEmpty(headPotrait)){
                List<String> picList = new ArrayList<>();
                picList.add(headPotrait);
                TaskBigImgActivity.startActivity(BuildAddActivity.this, (ArrayList<String>) picList, position);
            }
        }
    };

    private EnterpriseUserAdapter.OnChildDeleteClickListener noticeDelete = new EnterpriseUserAdapter.OnChildDeleteClickListener() {
        @Override
        public void onChildDeleteClick(int position, int childPosition) {
            User user = noticeConstructions.get(position).getUserList().get(childPosition);
            noticeConstructions.get(position).getUserList().remove(user);
            selectNotices.remove(user);
            if(noticeConstructions.get(position).getUserList().size() <= 0){
                noticeConstructions.remove(position);
            }
            noticeEnterpriseAdapter.setDataList(noticeConstructions);
        }
    };

    private  EnterpriseUserAdapter.OnChildHeadClickListener noticeHead = new EnterpriseUserAdapter.OnChildHeadClickListener() {
        @Override
        public void onChildHeadClick(int position, int childPosition) {
            String headPotrait = contactConstructions.get(position).getUserList().get(childPosition).getHeadPortrait();
            if(!Utils.isEmpty(headPotrait)){
                List<String> picList = new ArrayList<>();
                picList.add(headPotrait);
                TaskBigImgActivity.startActivity(BuildAddActivity.this, (ArrayList<String>) picList, position);
            }
        }
    };

    @OnClick({R.id.iv_back, R.id.save_test, R.id.inspect_date_tv, R.id.reply_date_tv, R.id.remind_date_tv, R.id.contact_tv, R.id.notice_tv})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.save_test:
                getMinImage();
                break;
            case R.id.inspect_date_tv:
                inspectTime.show();
                break;
            case R.id.reply_date_tv:
                replyTime.show();
                break;
            case R.id.remind_date_tv:
                remindeTime.show();
                break;
            case R.id.contact_tv:
                goToContacts();
                break;
            case R.id.notice_tv:
                goToNotices();
                break;
        }
    }

    private void getMinImage() {
        if (!checkContent()) {
            return;
        }

        if (paths.size() > 1) {
            Utils.startDownload(getResources().getString(R.string.loading), this);

            new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... voids) {
                    minPaths = new ArrayList<String>();
                    for (int i = 0; i < paths.size() - 1; i++) {
                        String path = FileUtil.imageDir1 + System.currentTimeMillis() + ".jpg";
                        FileUtil.writeByteArrayToPath(path, FileUtil.handleUploadImg(paths.get(i)));
                        minPaths.add(path);
                    }
                    return null;
                }


                @Override
                protected void onPostExecute(Void aVoid) {
                    addTest();
                }


            }.execute();
        } else {
            minPaths = new ArrayList<String>();
            addTest();
        }

    }

    private void addTest() {
        RequestParams params = new RequestParams();
        params.addBodyParameter("constructionId", SPUtil.getString(this, "constructionid"));
        params.addBodyParameter("inspectDate", inspectDateTv.getText().toString());
        params.addBodyParameter("deadlineReplyDate", replyDateTv.getText().toString());
        params.addBodyParameter("warningReminderDate", remindDateTv.getText().toString());
        params.addBodyParameter("items", testDetailEtv.getEditableText().toString() + " ");

        if(selectContacts != null && selectContacts.size()>0){
            JSONArray contactArray = new JSONArray();
            try {
                for(int i=0;i<selectContacts.size();i++) {
                    JSONObject object = new JSONObject();
                    if(fromEnterprise){
                        object.put("contactId",selectContacts.get(i).getId());
                        object.put("constructionId",selectContacts.get(i).getConstructionId());
                    }else {
                        object.put("contactId",selectContacts.get(i).getUserId());
                    }
                    object.put("userName",selectContacts.get(i).getName());
                    object.put("status",selectContacts.get(i).getStatus());
                    contactArray.put(object);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            params.addBodyParameter("contactList", contactArray.toString());
        }

        if(selectNotices != null && selectNotices.size()>0){
            JSONArray noticeArray = new JSONArray();
            try {
                for(int i=0;i<selectNotices.size();i++) {
                    JSONObject object = new JSONObject();
                    if(fromEnterprise){
                        object.put("userId",selectNotices.get(i).getId());
                        object.put("constructionId",selectNotices.get(i).getConstructionId());
                    }else {
                        object.put("userId",selectNotices.get(i).getUserId());
                    }
                    object.put("userName",selectNotices.get(i).getName());
                    object.put("status",selectNotices.get(i).getStatus());
                    noticeArray.put(object);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            params.addBodyParameter("notifyList", noticeArray.toString());
        }

        for (int i = 0; i < minPaths.size(); i++) {
            params.addBodyParameter("files[" + i + "]", new File(minPaths.get(i)));
        }

        params.addBodyParameter("createBy", SPUtil.getString(this, "userId"));

        Utils.requestData(getResources().getString(R.string.loading), this, "/build/batchSave/" + SPUtil.getString(this, "uuid"), params, new Utils.ListenerJson() {
            @Override
            public void onSuccess(String json) {
                try {
                    JSONObject object = new JSONObject(json);
                    int status = object.getInt("status");
                    if(status == 1){
                        showToast("提交成功");
                        setResult(1);
                        finish();
                    }else {
                        String msg = object.getString("msg");
                        showToast(msg);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    showToast("系统异常");
                }
            }

            @Override
            public void onFailure(String json) {
                try {
                    JSONObject object = new JSONObject(json);
                    String msg = object.getString("msg");
                    showToast(msg);
                } catch (JSONException e) {
                    e.printStackTrace();
                    showToast("系统异常");
                }
            }
        });

    }

    private boolean checkContent() {
        if (Utils.isEmpty(inspectDateTv.getText().toString())) {
            showToast("请选择任务日期");
            return false;
        }

        if (Utils.isEmpty(replyDateTv.getText().toString())) {
            showToast("请选择限期回复时间");
            return false;
        }

        if (Utils.isEmpty(remindDateTv.getText().toString())) {
            showToast("请选择预警提醒时间");
            return false;
        }

        if(remideDate.getTime() <= inspectDate.getTime()){
            showToast("预警提醒时间必须大于任务日期");
            return false;
        }

        if(replyDate.getTime() <= remideDate.getTime()){
            showToast("预警提醒时间必须小于限期回复时间");
            return false;
        }

        if (Utils.isEmpty(testDetailEtv.getEditableText().toString())) {
            showToast("请填写任务信息");
            return false;
        }

        if(selectContacts.size() <= 0){
            showToast("请选择责任人");
            return false;
        }

//        if(minPaths.size() <= 0){
//            showToast("请选择附件");
//            return false;
//        }

        return true;
    }

    private List<User> userPurify(List<User> users){
        Iterator<User> iterator = users.iterator();
        while (iterator.hasNext()){
            User user = iterator.next();
            if(user.equals(getAddUser())){
                iterator.remove();
            }
        }
        return users;
    }

    private User getAddUser() {
        User addUser = new User();
        addUser.setHeadPortrait(Utils.ADDPIC);
        addUser.setUserId("-1");
        addUser.setName("");
        return addUser;
    }

    private LinearLayoutManager getHorizontalLinearLayoutManager() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        return linearLayoutManager;
    }

    private LinearLayoutManager getVerticalLinearLayoutManager() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        return linearLayoutManager;
    }

    @Override
    public void onItemClick(View v, int position) {
        Intent intent;
        if (paths.get(position).equals(Utils.ADDPIC)) {
            List<String> tempStrings = new ArrayList<String>();
            tempStrings.addAll(paths);
            tempStrings.remove(tempStrings.size() - 1);
            MultiImageSelector.create()
                    .showCamera(true) // show camera or not. true by default_grey
                    .count(9) // max select image size, 9 by default_grey. used width #.multi()
                    .multi()
                    .origin((ArrayList<String>) tempStrings)
                    .start(this, ADD_PIC);
        } else {
            paths.remove(position);
            aualityTestAddPicAdapter.notifyDataSetChanged();
        }
    }

    private void initTimePicker() {
        Date today = new Date();
        inspectDate = today;
        inspectDateTv.setText(getDate(today));
//        replyDateTv.setText(getTime(today));
//        remindDateTv.setText(getTime(today));

        Calendar selectedDate = Calendar.getInstance();//系统当前时间
        selectedDate.setTime(today);
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.set(1970, 0, 1);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.set(2100, 0, 1);

        inspectTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                inspectDate = date;
                inspectDateTv.setText(getDate(date));
            }
        }).setType(new boolean[]{true, true, true, false, false, false})//年月日时分秒 的显示与否，不设置则默认全部显示
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(false)
                .setDividerColor(Color.GRAY)
                .setTextColorCenter(Color.BLUE)//设置选中项的颜色
                .setTextColorOut(Color.GRAY)//设置没有被选中项的颜色
                .setContentSize(16)
                .setDate(selectedDate)
                .setLineSpacingMultiplier(2.0f)
                .setTextXOffset(-10, -10, -10, -10, -10, -10)//设置X轴倾斜角度[ -90 , 90°]
                .setRangDate(startCalendar, endCalendar)
//                .setBackgroundId(0x00FFFFFF) //设置外部遮罩颜色
                .setDecorView(null)
                .build();

        replyTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                replyDate = date;
                replyDateTv.setText(getTime(date));
            }
        }).setType(new boolean[]{true, true, true, true, true, false})//年月日时分秒 的显示与否，不设置则默认全部显示
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(false)
                .setDividerColor(Color.GRAY)
                .setTextColorCenter(Color.BLUE)//设置选中项的颜色
                .setTextColorOut(Color.GRAY)//设置没有被选中项的颜色
                .setContentSize(16)
                .setDate(selectedDate)
                .setLineSpacingMultiplier(2.0f)
                .setTextXOffset(-10, -10, -10, -10, -10, -10)//设置X轴倾斜角度[ -90 , 90°]
                .setRangDate(startCalendar, endCalendar)
//                .setBackgroundId(0x00FFFFFF) //设置外部遮罩颜色
                .setDecorView(null)
                .build();

        remindeTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                remideDate = date;
                remindDateTv.setText(getTime(date));
            }
        }).setType(new boolean[]{true, true, true, true, true, false})//年月日时分秒 的显示与否，不设置则默认全部显示
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(false)
                .setDividerColor(Color.GRAY)
                .setTextColorCenter(Color.BLUE)//设置选中项的颜色
                .setTextColorOut(Color.GRAY)//设置没有被选中项的颜色
                .setContentSize(16)
                .setDate(selectedDate)
                .setLineSpacingMultiplier(2.0f)
                .setTextXOffset(-5, -5, -5, -5, -5, -5)//设置X轴倾斜角度[ -90 , 90°]
                .setRangDate(startCalendar, endCalendar)
//                .setBackgroundId(0x00FFFFFF) //设置外部遮罩颜色
                .setDecorView(null)
                .build();
    }

    private String getDate(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }

    private String getTime(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(date);
    }

}
